package com.burgess.net.visual;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * 接受者队列
 * 创建人    BurgessLee
 * 创建时间   2020/5/31
 * 描述
 */
public class QueueReceiver02 {

    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);

        Destination destination = session.createQueue("Consumer.B.VirtualTopic.TopicSender");
        MessageConsumer consumer = session.createConsumer(destination);

        consumer.setMessageListener(new MessageListener() {
            public void onMessage(Message message) {
                TextMessage txtMsg = (TextMessage)message;
                try{
                    System.out.println("receive02: " + txtMsg.getText());
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
        });


        session.commit();
        session.close();
        connection.close();
    }

}
